package io.shuttle.mbe.api

import io.shuttle.mbe.api.annotation.ChromeMinVersion
import io.shuttle.mbe.api.annotation.ChromeOSOnly
import io.shuttle.mbe.api.annotation.PromiseStyleMinVersion
import io.shuttle.mbe.api.types.Value1Function
import io.shuttle.mbe.core.Promise

////////////////////
// Idle
////////////////////
/**
 * Use the `Browser.idle` API to detect when the machine's idle state changes.
 *
 * Permissions: "idle"
 */
interface Idle {

    // Gets the time, in seconds, it takes until the screen is locked automatically while idle.
    // Returns a zero duration if the screen is never locked automatically.
    // Currently supported on Chrome OS only.
    // @return {callback.delay} Time, in seconds, until the screen is locked automatically while idle.
    // This is zero if the screen never locks automatically.
    @ChromeMinVersion(73)
    @ChromeOSOnly
    @PromiseStyleMinVersion(116)
     fun getAutoLockDelay(
        callback: Value1Function<Number>? = null
    ): Promise<Number>

    // Returns "locked" if the system is locked, "idle" if the user has not generated any input for a specified number of seconds,
    // or "active" otherwise.
    // @return {callback.newState}
    @PromiseStyleMinVersion(116)
     fun queryState(
        // The system is considered idle if detectionIntervalInSeconds seconds have elapsed since the last user input detected.
        detectionIntervalInSeconds: Number,
        callback: Value1Function<IdleState>? = null
    ): Promise<IdleState>

    // Sets the interval, in seconds, used to determine when the system is in an idle state for onStateChanged events.
    // The default interval is 60 seconds.
     fun setDetectionInterval(
        // Threshold, in seconds, used to determine when the system is in an idle state.
        intervalInSeconds: Number
    )

    // Fired when the system changes to an active, idle or locked state.
    // The event fires with "locked" if the screen is locked or the screensaver activates,
    // "idle" if the system is unlocked and the user has not generated any input for a specified number of seconds,
    // and "active" when the user generates input on an idle system.
     val onStateChanged: Events.Event<Value1Function<IdleState>>

    @ChromeMinVersion(44)
    enum class IdleState {
        active,
        idle,
        locked
    }
}